package cn.tedu.lucky.draw.server.controller;

import cn.tedu.lucky.draw.server.common.result.JsonResult;
import cn.tedu.lucky.draw.server.protocol.po.Rule;
import cn.tedu.lucky.draw.server.protocol.query.RuleQuery;
import cn.tedu.lucky.draw.server.service.IRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class RuleController {

    @Autowired
    private IRuleService ruleService;

    @PostMapping("/draw/rule/findAll")
    public JsonResult<List<Rule>> findAll(@RequestBody RuleQuery ruleQuery){
        List<Rule> ruleList = ruleService.findAll(ruleQuery);
        return JsonResult.ok(ruleList);
    }

    @PostMapping("/draw/rule/save")
    public JsonResult save(@RequestBody Rule rule){
        ruleService.save(rule);
        return JsonResult.ok();
    }

    @GetMapping("/draw/activity-rule/findRule/{id}")
    public JsonResult<List<Rule>> findRulesByActivityId(@PathVariable("id") Long activityId){
        List<Rule> ruleList = ruleService.findRulesByActivityId(activityId);
        return JsonResult.ok(ruleList);
    }

    @GetMapping("/draw/activity-rule/noBindRule/{id}")
    public JsonResult<List<Rule>> findNoBindRuleByActivityId(@PathVariable("id") Long activityId){
        List<Rule> ruleList = ruleService.findNoBindRuleByActivityId(activityId);
        return JsonResult.ok(ruleList);
    }
}
